<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存盘点预警管理</title>
	<meta name="decorator" content="default"/>
</head>
<body>
	<div class="icon-buttons">
		<input type="button" class="leave-clean-session" data-inline="true" data-icon="back" data-iconpos="notext" value="返回"/>
	</div>
	<form:form id="searchForm" modelAttribute="storeInventoryAlert" action="${ctx}/inventory/storeInventoryAlert/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="middleCls">
			<a href="${ctx}/inventory/storeInventoryAlert/form" data-role="button" data-inline="true">预警产品添加</a>
	     	<input type="search" placeholder="产品名称" name="procuctName" id="procuctName" value="${procuctName}" data-inline="true">
			<input type="submit" data-inline="true" value="查询"/>
		</div>
	</form:form>
	<tags:message content="${message}"/>
	<div class="form-input">
		<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
			<thead><tr><th>产品渠道</th><th>产品名称</th><th>预警值</th><th></th></tr></thead>
			<tbody>
			<c:forEach items="${page.list}" var="storeInventoryAlert">
				<tr id="${storeInventoryAlert.id}">
					<td>
						${fns:getDictLabel(storeInventoryAlert.storeProduct.product_type, "product_type", "")}
					</td>
					<td>
						<c:if test="${storeInventoryAlert.storeProduct.product_type == 0}">
							${storeInventoryAlert.storeProduct.product.name}
						</c:if>
						<c:if test="${storeInventoryAlert.storeProduct.product_type == 1}">
							${storeInventoryAlert.storeProduct.storeSelfProduct.name}
						</c:if>
					</td>
					<td>${storeInventoryAlert.alertAmount}</td>
					<td class="operateTD" id="${storeInventoryAlert.id}">
						<input type="button" data-inline="true" data-icon="arrow-d" data-iconpos="notext">
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<div class="pagination">${page}</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#contentTable tbody tr").click(function(e){
				if (!this.id) {
					return;
				}
				$(this).addClass("opreationTR");
				operateMenu(this.id);
			});
			$("body").click(function(e){
				$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
				$(".opreationTR").removeClass("opreationTR");
				$(".opreation").remove();
			});
		});
		var item;
		function operateMenu(id){
			item = $("#opreation-"+ id);
			$(".opreationTR").removeClass("opreationTR");
			$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
			if(item.length > 0) {
				item.remove();
				this.event.stopPropagation();
				return;
			}
			$("#"+id + " .ui-icon-arrow-d").removeClass("ui-icon-arrow-d").addClass("ui-icon-arrow-u");
			$(".opreation").remove();
			var url = "${ctx}/inventory/storeInventoryAlert/form?id=" + id;
			var html= "<tr id='opreation-" + id + "' class='opreation'><td colspan='4'>";
				html += "<a data-role='button' data-inline='true' href='" + url+ "'>修改</a>";
				html += "<a class='menu-del' data-role='button' data-inline='true' href='#'>删除</a></td></tr>";
			var del = function(){
				var url = "${ctx}/inventory/storeInventoryAlert/delete?id=" + id;
				bossLoginDeletePopup("确定要删除此产品的预警？", url);
			};
			
			$(".menu-del").die().live('click',del);
			$("#" + id).addClass("opreationTR");
			$("#" + id).after(html);
			$("#contentTable").trigger("create");
			this.event.stopPropagation();
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</body>
</html>
